package com.yc.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.bean.TestResult;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface TestResultDao extends BaseMapper<TestResult> {
    
    /**
     * 根据记录ID查询测评结果
     */
    @Select("SELECT tr.*, pt.title " +
            "FROM testResults tr " +
            "INNER JOIN psychologicalTests pt ON tr.testId = pt.testId " +
            "WHERE tr.recordId = #{recordId}")
    TestResult selectByRecordId(@Param("recordId") Long recordId);
    
    /**
     * 根据用户ID和测评ID查询最新结果
     */
    @Select("SELECT tr.*, pt.title " +
            "FROM testResults tr " +
            "INNER JOIN psychologicalTests pt ON tr.testId = pt.testId " +
            "WHERE tr.userId = #{userId} AND tr.testId = #{testId} " +
            "ORDER BY tr.createTime DESC LIMIT 1")
    TestResult selectLatestResult(@Param("userId") Long userId, @Param("testId") Long testId);
} 